#ifndef _GRAPHICS_H_
#define _GRAPHICS_H_

#include "SDL.h"
#include "SDL_image.h"
#include "SDL_ttf.h"
#include <string>

/* The graphics namespace is designed to allow the rest of the
game graphics run regardless of which graphics library is being used. */

namespace Graphics
{
	class Screen;
	class Texture;
	class Colour;
	class Font;
	class Rect;

	bool init_graphics(); // Initialise SDL, initialise SDL_ttf, OTHER LIBS
	void cleanup_graphics(); // Cleanup SDL, initialise SDL_ttf, OTHER LIBS

	class Screen
	{
	public:
		Screen( int width, int height, std::string title ); // Create the screen surface
		~Screen();

		void begin(); // clear the surface
		void end(); // Flip the surface
		void draw( int x, int y, Texture* texture ); // Blit a texture
		void draw( int x, int y, Texture* texture, Rect* clip ); // Blit a clipped area of a texture
		void draw_rect( int x, int y, int width, int height, Colour* colour ); // Draw a rectangle
		void draw_string( int x, int y, std::string text, Font* font, Colour* colour ); // Draw a string
		
	private:
		SDL_Surface* screen; // the main SDL surface to be used as the display
		Uint32 clear_colour; // The colour to clear the screen to
	};

	class Texture
	{
	public:
		Texture( std::string filepath ); // Load the file
		~Texture();

	private:
		SDL_Surface* image;
		float width;
		float height;

		friend class Screen; // Ensure that the Screen can draw the texture
	};

	class Colour
	{
	public:
		Colour();
		~Colour();

		static Colour* fromRGB(int red, int green, int blue);
	private:
		int r;
		int g;
		int b;

		friend class Screen; // Ensure that the screen can access the colour properties
	};

	class Font
	{
	public:
		Font();
		Font( std::string filename, int size );
		~Font();

	private:
		TTF_Font* font;

		friend class Screen;
	};

	class Rect
	{
	public:
		Rect();
		Rect( int x, int y, int w, int h );
		~Rect();

		/*int x();
		int y();
		int width();
		int height();*/ // Decision needs to be made about accessing values

		bool intersects( Rect* otherRect );
	private:
		SDL_Rect rect;

		friend class Screen;
	};
};

#endif